﻿using System.Collections.Generic;
using Missbot.Service;

namespace Missbot.AIModule.Pet.Expedition
{
    public class ExpeditionHistory : DbBaseEntity
    {
        public string UserID { get; set; }

        public Dictionary<string, int> SceneDic { get; set; } = new();

        public int EnduranceConsume { get; set; }

        public int ItemBonusCount { get; set; }

        public int ItemBonusPriceTotal { get; set; }

        public int GoldsTotal { get; set; }

        public int FlavoringTotal { get; set; }
    }

    public static class ExpeditionHistoryDA
    {
        public static ExpeditionHistory Get(string UserID)
        {
            var rec = MongoService<ExpeditionHistory>.GetOnly(p => p.UserID == UserID);
            if (rec != null)
            {
                return rec;
            }

            rec = new ExpeditionHistory {UserID = UserID};
            MongoService<ExpeditionHistory>.Insert(rec);

            return rec;
        }

        public static void AddScene(this ExpeditionHistory entity, string scene)
        {
            if (!entity.SceneDic.ContainsKey(scene))
            {
                entity.SceneDic.Add(scene, 0);
            }

            entity.SceneDic[scene]++;
        }

        public static void Update(this ExpeditionHistory entity)
        {
            MongoService<ExpeditionHistory>.Update(entity);
        }
    }
}